﻿@using Board.Models

@{
    ViewBag.Title = "User Detail";
}

<h2>UserDetail</h2>

@if (ViewBag.User != null)
{
    WebUser user = (WebUser) ViewBag.User;
    WebUser creator = new WebUser(user.CreatedBy);
    <text>
        <div id="UserInfoDiv">
            <fieldset>
                <legend>t_UserProfile</legend>

                <div class="display-label">
                    User ID
                </div>
                <div class="display-field">
                    @(user.UserId) @Html.Hidden("userId", user.UserId)
                </div>

                <div class="display-label">
                    Username
                </div>
                <div class="display-field">
                    @user.Username
                </div>

                <div class="display-label">
                    First Name
                </div>
                <div class="display-field">
                    @(user.FirstName)
                </div>

                <div class="display-label">
                    Last Name
                </div>
                <div class="display-field">
                    @(user.LastName)
                </div>

                <div class="display-label">
                    User Type
                </div>
                <div class="display-field">
                    @(user.UserType)
                </div>

                <div class="display-label">
                    Creation Date
                </div>
                <div class="display-field">
                    @(user.CreationDate)
                </div>

                <div class="display-label">
                    Show All Beds<br />in one screen
                </div>
                <div class="display-field">
                    @(user.ShowAllBed.ToString())
                </div>

                <div class="display-label">
                    Created By
                </div>
                <div class="display-field">
                    @(creator.UserId > 0 ? creator.FullName : "")
                </div>

                <div class="display-label">
                    Default Site
                </div>
                <div class="display-field">
                    @(user.DefaultSite!=null?user.DefaultSite.SiteId:"")
                </div>

                <div class="display-label">
                    Default Unit
                </div>
                <div class="display-field">
                    @(user.DefaultUnit==null?"":user.DefaultUnit.UnitId)
                </div>
                
                <div class="display-label">
                    Display records per page
                </div>
                <div class="display-field">
                    @(user.DefaultRecordsPerPage)
                </div>

                <div class="display-label">
                    User Role
                </div>
                <div class="display-field">
                    @(string.Join(", ", user.Roles.Select(r=>r.RoleName)))
                </div>
                
                <div class="display-label">
                    Password
                </div>
                <div class="display-field">
                    <div id="jqueryFormDiv">
                        <a href="javascript:void(0);" onclick="SendRequest('/Account/ResetPassword/?userId=@(user.UserId)', {}, 'jqueryFormDiv')">Reset</a>
                    </div>
                </div>

            </fieldset>
        </div>
        <p>
            @Html.ActionLink("Edit", "UserModify", new {userId=user.UserId }) 
            @if (Tools.CurrentUser.HasSomeAdminPermission)
            {
                <text>
                    |
            @Html.ActionLink("Back to List", "UserList")
                </text>
            }
        </p>
        <h2>Accessible Units</h2>
        <div id="userPermissionDiv">
            <div id="changePermissions" class="change-permissions"><a href="javascript:void(0);">Change Permissions</a></div>
            @foreach (Site site in user.AccessibleSites) { 
                <text>
                    <div class="site-div">
                        <h4>Site @site.SiteId</h4>
                        @foreach (Unit unit in site.AccessibleUnit.ToList().OrderBy(u=>u.UnitId)) { 
                            <text>
                                <div class="unit-div">
                                    <h6>Unit @unit.UnitId</h6>
                                    @foreach (Bed bed in unit.AccessibleBeds.ToList().OrderBy(b=>b.BedId)) { 
                                        <text>
                                            <div class="bed-div status-@(bed.BedStatus)@(string.IsNullOrEmpty(bed.BedType)?"":" "+bed.BedType)">@bed.BedId</div>
                                        </text>
                                    }
                                </div>
                            </text>
                        }
                    </div>
                </text>
            }
        </div>
    </text>
}


@section Scripts {
    <script src="~/Scripts/account.js"></script>
}